package interview.juc.task;

import io.netty.util.concurrent.DefaultThreadFactory;
import util.ThreadUtil;

import java.util.concurrent.*;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/30 10:59
 */
public class FutureTaskDemo1 implements Runnable{
    @Override
    public void run() {
        System.out.println("出去买酒");
        ThreadUtil.sleep(5000);
        System.out.println("买酒回来了");
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executor = new ThreadPoolExecutor(5,5,10, TimeUnit.SECONDS
                ,new ArrayBlockingQueue<>(10),new DefaultThreadFactory("test"));
        FutureTaskDemo1 demo = new FutureTaskDemo1();
        FutureTaskDemo2 demo2 = new FutureTaskDemo2();
        executor.submit(demo).get();
        executor.submit(demo2);
        executor.shutdown();
    }

}
